import pygame

from sprite.move_sprite import MoveSprite


class Missle(MoveSprite):
    width = 10
    height = 10
    images = {
        'U': pygame.image.load('images/missleU.gif'),
        'D': pygame.image.load('images/missleD.gif'),
        'L': pygame.image.load('images/missleL.gif'),
        'R': pygame.image.load('images/missleR.gif')
    }

    def __init__(self):
        super().__init__()
        self.speed = 7
        self.active = True
        # 移动状态
        self.moveState = True

    # 获取surface
    def get_surface(self):
        return self.images[self.direction]

    def setTank(self, tank):
        self.direction = tank.direction
        # 位置
        self.postion.left = tank.postion.left + (tank.width - self.width + 8) / 2
        self.postion.top = tank.postion.top + (tank.height - self.height) / 2

    # 移动
    def move(self, screen):
        if self.active:
            if self.direction == 'L':
                self.postion.left -= self.speed
                if self.postion.left < 0:
                    self.active = False
            elif self.direction == 'R':
                self.postion.left += self.speed
                if self.postion.right > screen.get_width():
                    self.active = False
            elif self.direction == 'U':
                self.postion.top -= self.speed
                if self.postion.top < 0:
                    self.active = False
            elif self.direction == 'D':
                self.postion.top += self.speed
                if self.postion.bottom > screen.get_height():
                    self.active = False
